package com.edu.exam.entity.assessment.technical;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 批量查重任务实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：batch_check_task
 *
 * 根据B-02-06试题查重子模块设计文档实现
 * 管理批量查重任务，支持任务调度、进度监控和结果汇总。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "batch_check_task")
@Comment("批量查重任务表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QuestionBatchCheckTask {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 批量查重任务唯一标识符
     */
    @NotBlank(message = "批量查重任务ID不能为空")
    @Size(max = 50, message = "批量查重任务ID长度不能超过50个字符")
    @Column(name = "task_id", nullable = false, length = 50, unique = true)
    private String taskId;

    /**
     * 任务名称
     */
    @NotBlank(message = "任务名称不能为空")
    @Size(max = 200, message = "任务名称长度不能超过200个字符")
    @Column(name = "task_name", nullable = false, length = 200)
    private String taskName;

    /**
     * 任务描述
     */
    @Size(max = 1000, message = "任务描述长度不能超过1000个字符")
    @Column(name = "task_description", columnDefinition = "TEXT")
    private String taskDescription;

    /**
     * 任务状态（PENDING-待执行，RUNNING-执行中，COMPLETED-已完成，FAILED-失败，CANCELLED-已取消）
     */
    @NotBlank(message = "任务状态不能为空")
    @Size(max = 20, message = "任务状态长度不能超过20个字符")
    @Column(name = "task_status", nullable = false, length = 20)
    private String taskStatus;

    /**
     * 查重范围（ALL-所有试题，LIBRARY-指定题库，SUBJECT-指定学科，DIFFICULTY-指定难度）
     */
    @NotBlank(message = "查重范围不能为空")
    @Size(max = 20, message = "查重范围长度不能超过20个字符")
    @Column(name = "check_scope", nullable = false, length = 20)
    private String checkScope;

    /**
     * 查重范围参数（JSON格式，存储具体的范围参数）
     */
    @Column(name = "scope_params", columnDefinition = "TEXT")
    private String scopeParams;

    /**
     * 算法配置（JSON格式，指定使用的算法和参数）
     */
    @Column(name = "algorithm_config", columnDefinition = "TEXT")
    private String algorithmConfig;

    /**
     * 相似度阈值
     */
    @Column(name = "similarity_threshold")
    private Double similarityThreshold;

    /**
     * 启用的算法列表（JSON数组格式）
     */
    @Column(name = "enabled_algorithms", columnDefinition = "TEXT")
    private String enabledAlgorithms;

    /**
     * 优先级（1-5，数字越大优先级越高）
     */
    @Column(name = "priority_level")
    private Integer priorityLevel;

    /**
     * 计划开始时间
     */
    @Column(name = "scheduled_start_time")
    private LocalDateTime scheduledStartTime;

    /**
     * 实际开始时间
     */
    @Column(name = "start_time")
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    @Column(name = "end_time")
    private LocalDateTime endTime;

    /**
     * 预计完成时间
     */
    @Column(name = "estimated_completion_time")
    private LocalDateTime estimatedCompletionTime;

    /**
     * 总试题数量
     */
    @Column(name = "total_questions")
    private Integer totalQuestions;

    /**
     * 已处理试题数量
     */
    @Column(name = "processed_questions")
    private Integer processedQuestions;

    /**
     * 发现相似试题数量
     */
    @Column(name = "similar_questions_found")
    private Integer similarQuestionsFound;

    /**
     * 高相似度试题数量
     */
    @Column(name = "high_similarity_questions")
    private Integer highSimilarityQuestions;

    /**
     * 中相似度试题数量
     */
    @Column(name = "medium_similarity_questions")
    private Integer mediumSimilarityQuestions;

    /**
     * 低相似度试题数量
     */
    @Column(name = "low_similarity_questions")
    private Integer lowSimilarityQuestions;

    /**
     * 处理进度（百分比）
     */
    @Column(name = "progress_percentage")
    private Double progressPercentage;

    /**
     * 执行器ID（标识任务在哪个节点执行）
     */
    @Size(max = 50, message = "执行器ID长度不能超过50个字符")
    @Column(name = "executor_id", length = 50)
    private String executorId;

    /**
     * 执行器节点信息
     */
    @Size(max = 200, message = "执行器节点信息长度不能超过200个字符")
    @Column(name = "executor_node_info", length = 200)
    private String executorNodeInfo;

    /**
     * 批次大小（每批处理的试题数量）
     */
    @Column(name = "batch_size")
    private Integer batchSize;

    /**
     * 当前批次编号
     */
    @Column(name = "current_batch")
    private Integer currentBatch;

    /**
     * 总批次数
     */
    @Column(name = "total_batches")
    private Integer totalBatches;

    /**
     * 处理速度（每分钟处理试题数）
     */
    @Column(name = "processing_speed")
    private Double processingSpeed;

    /**
     * 剩余时间估算（分钟）
     */
    @Column(name = "estimated_remaining_time")
    private Long estimatedRemainingTime;

    /**
     * 任务失败原因
     */
    @Size(max = 1000, message = "任务失败原因长度不能超过1000个字符")
    @Column(name = "failure_reason", columnDefinition = "TEXT")
    private String failureReason;

    /**
     * 错误详情（JSON格式）
     */
    @Column(name = "error_details", columnDefinition = "TEXT")
    private String errorDetails;

    /**
     * 重试次数
     */
    @Column(name = "retry_count")
    private Integer retryCount;

    /**
     * 最大重试次数
     */
    @Column(name = "max_retry_count")
    private Integer maxRetryCount;

    /**
     * 任务结果摘要（JSON格式）
     */
    @Column(name = "result_summary", columnDefinition = "TEXT")
    private String resultSummary;

    /**
     * 任务日志（JSON格式，存储关键操作日志）
     */
    @Column(name = "task_log", columnDefinition = "TEXT")
    private String taskLog;

    /**
     * 输出配置（JSON格式，指定结果输出方式）
     */
    @Column(name = "output_config", columnDefinition = "TEXT")
    private String outputConfig;

    /**
     * 输出文件路径
     */
    @Size(max = 500, message = "输出文件路径长度不能超过500个字符")
    @Column(name = "output_file_path", length = 500)
    private String outputFilePath;

    /**
     * 通知配置（JSON格式，指定任务完成后的通知方式）
     */
    @Column(name = "notification_config", columnDefinition = "TEXT")
    private String notificationConfig;

    /**
     * 是否已通知
     */
    @Column(name = "notification_sent")
    private Boolean notificationSent;

    /**
     * 创建者ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}